Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.
We test here a few map examples using cartopy.
In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (16, 10)
In [ ]:
import cartopy.crs as ccrs
There is a list of the available map projections in Cartopy.
In [ ]:
# Set the projection to use
ax = plt.axes(projection=ccrs.PlateCarree())
# Draw coastlines
ax.coastlines();
In [ ]:
ax = plt.axes(projection=ccrs.Mollweide())
# Add a land image
ax.stock_img();
This has been taken from the gallery
In [ ]:
fig = plt.figure(figsize=(16, 10))
# Set the projection to use
ax = fig.add_subplot(1, 1, 1, projection=ccrs.Robinson())
# make the map global rather than have it zoom in to
# the extents of any plotted data
ax.set_global()
# Add a land image
ax.stock_img()
# Draw coastlines
ax.coastlines()
# Plot a point
ax.plot(-0.08, 51.53, 'o', color="r", markersize=8, transform=ccrs.PlateCarree())
# Draw a straight line
ax.plot([-0.08, 132], [51.53, 43.17], linewidth=3, transform=ccrs.PlateCarree())
# Draw a geodetic line
ax.plot([-0.08, 132], [51.53, 43.17], linewidth=3, transform=ccrs.Geodetic());
In [ ]:
# Set the projection to use
ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img();
ny_lon, ny_lat = -75, 43
delhi_lon, delhi_lat = 77.23, 28.61
# Draw a geodetic line
plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat],
color='blue', linewidth=2, marker='o', transform=ccrs.Geodetic())
# Draw a straight line
plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat],
color='gray', linestyle='--', transform=ccrs.PlateCarree())
# Write two labels
plt.text(ny_lon-3, ny_lat-12, 'New York',
horizontalalignment='right', transform=ccrs.Geodetic())
plt.text(delhi_lon+3, delhi_lat-12, 'Delhi',
horizontalalignment='left', transform=ccrs.Geodetic());
In [ ]: